package com.brsya.movie.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.brsya.base.bean.InventoryBean;
import com.brsya.base.recycler.BaseAdapter;
import com.brsya.base.recycler.BaseViewHolder;
import com.brsya.base.util.GlideUtil;
import com.brsya.movie.R;

import java.util.List;
import java.util.Locale;

/**
 * Created by Brsya
 * CreateDate: 2022/7/7  9:59
 * Description:
 * 片单列表
 */
public class InventoryListAdapter extends BaseAdapter<InventoryBean> {
    private final Context context;

    public InventoryListAdapter(Context context) {
        this.context = context;
    }

    @Override
    public BaseViewHolder onCreate(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(context).inflate(R.layout.item_inventory, parent, false);
        return new BaseViewHolder(rootView);
    }

    @Override
    public void onBind(BaseViewHolder viewHolder, int RealPosition, InventoryBean data) {
        ImageView ivInventoryImg3 = viewHolder.findViewById(R.id.iv_inventory_img_3);
        ImageView ivInventoryImg2 = viewHolder.findViewById(R.id.iv_inventory_img_2);
        ImageView ivInventoryImg1 = viewHolder.findViewById(R.id.iv_inventory_img_1);
        TextView tvInventoryName = viewHolder.findViewById(R.id.tv_inventory_name);
        TextView tvInventoryNumber = viewHolder.findViewById(R.id.tv_inventory_number);
        TextView tvInventoryInfo = viewHolder.findViewById(R.id.tv_inventory_info);


        List<InventoryBean.VideoListDTO> videoList = data.getVideoList();
        String imgUrl1 = "";
        String imgUrl2 = "";
        String imgUrl3 = "";
        if (videoList != null) {
            for (int i = 0; i < videoList.size() && i < 3; i++) {
                InventoryBean.VideoListDTO video = videoList.get(i);
                switch (i) {
                    case 0:
                        imgUrl1 = video.getCoverUrl();
                        break;
                    case 1:
                        imgUrl2 = video.getCoverUrl();
                        break;
                    case 2:
                        imgUrl3 = video.getCoverUrl();
                        break;
                    default:
                        break;
                }
            }
            tvInventoryNumber.setText(String.format(Locale.getDefault(), "共%d部", videoList.size()));
        }
        // TODO: 2022/7/7 加载失败图片
        GlideUtil.loadRound(ivInventoryImg1, imgUrl1, 4, com.brsya.base.R.mipmap.logo);
        GlideUtil.loadRound(ivInventoryImg2, imgUrl2, 4, com.brsya.base.R.mipmap.logo);
        GlideUtil.loadRound(ivInventoryImg3, imgUrl3, 4, com.brsya.base.R.mipmap.logo);
        tvInventoryName.setText(data.getTitle());
        tvInventoryInfo.setText(data.getContent());
    }
}
